using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using ZoneFiveSoftware.Common.Visuals;
using FilteredStatistics.Controller;
using FilteredStatistics.Data;

namespace FilteredStatistics.View
{
    class FilteredStatisticsTreeListLabelProvider : TreeList.DefaultLabelProvider
    {
        public override string GetText(object element, TreeList.Column column)
        {
            try
            {
                TreeListColumnInfo columnInfo = Options.Instance.StatisticsColumnsManager.FindColumn(new Guid(column.Id));

                if (element is RangeWrapper)
                {
                    RangeWrapper range = element as RangeWrapper;

                    return columnInfo.Provider.GetStatisticLabel(columnInfo.Id, range.InfoCache);
                }
                else if (element is TotalStatsWrapper)
                {
                    TotalStatsWrapper totalWrapper = element as TotalStatsWrapper;

                    List<object> allRanges = new List<object>();

                    foreach (ActivityRangeInfoCache range in totalWrapper.AllRanges)
                    {
                        allRanges.Add(range);
                    }

                    return columnInfo.Provider.GetTotalStatisticLabel(columnInfo.Id, allRanges);
                }

                return String.Empty;
            }
            catch(Exception e)
            {
                Debug.Assert(false, "Exception in Statistics provider", e.Message + "\n\nStack: " + e.StackTrace);
                return String.Empty;
            }
        }
    }
}
